hackerrank ruby array selection solution